/*
 * Copyright 2010 Gal Dolber.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.guit.demo.client.complexplace;

import com.google.inject.Inject;

import com.guit.demo.client.complexplace.ComplexPlacePresenter.ComplexPlaceBinder;
import com.guit.demo.client.main.MainPresenter;
import com.guit.junit.GuitTest;

import static junit.framework.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TestComplexPlacePresenter extends GuitTest {

  @Inject
  ComplexPlacePresenter presenter;

  @Override
  protected void configure() {
    mock(ComplexPlaceBinder.class);
    mock(MainPresenter.class);
  }

  @Before
  public void initialize() {
    presenter.go(null);
  }

  @Test
  public void testPojoEquals() {
    assertEquals(presenter.checkbox, presenter.checkbox);
  }

  @Test
  public void testCheckbox() {
    assertEquals(presenter.data.isEnabled(), true);

    presenter.checkbox.setValue(false);
    presenter.checkboxOrTextboxChange(presenter.checkbox);
    assertEquals(presenter.data.isEnabled(), false);

    presenter.checkbox.setValue(true);
    presenter.checkboxOrTextboxChange(presenter.checkbox);

    assertEquals(presenter.data.isEnabled(), true);
  }

  @Test
  public void testClickBox() {
    assertEquals(presenter.data.getColor(), "red");

    presenter.color.setBackgroundColor("red");
    presenter.color$click();
    assertEquals(presenter.data.getColor(), "blue");

    presenter.color.setBackgroundColor("blue");
    presenter.color$click();
    assertEquals(presenter.data.getColor(), "red");
  }

  @Test
  public void testTextbox() {
    assertEquals(presenter.data.getText(), "Hello");

    String goodbye = "Goodbye";
    presenter.textbox.setText(goodbye);
    presenter.checkboxOrTextboxChange(presenter.textbox);
    assertEquals(presenter.data.getText(), goodbye);

    String guitRocks = "Guit Rocks!";
    presenter.textbox.setText(guitRocks);
    presenter.checkboxOrTextboxChange(presenter.textbox);
    assertEquals(presenter.data.getText(), guitRocks);
  }
}
